package com.kymatrix.mpo.plus.bpm.server.model.form.activity;

import com.kymatrix.mpo.plus.common.util.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.experimental.Accessors;
import org.flowable.engine.history.HistoricActivityInstance;

@ApiModel(value = "管理后台 - 流程活动的 Response")
@Data
@Accessors(chain=true)
public class QueryBpmActivityResp {

    @ApiModelProperty(value = "流程活动的标识", example = "1024")
    private String key;
    @ApiModelProperty(value = "流程活动的类型", example = "StartEvent")
    private String type;

    @ApiModelProperty(value = "流程活动的开始时间")
    private LocalDateTime startTime;
    @ApiModelProperty(value = "流程活动的结束时间")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "关联的流程任务的编号", example = "2048")
    private String taskId; // 关联的流程任务，只有 UserTask 等类型才有
    
    public static QueryBpmActivityResp fromEntity(HistoricActivityInstance bean) {
        if (bean == null) {
            return null;
        }
        QueryBpmActivityResp res = new QueryBpmActivityResp();
        res.setKey(bean.getActivityId());
        res.setType(bean.getActivityType());
        res.setStartTime(DateUtil.of(bean.getStartTime()));
        res.setEndTime(DateUtil.of(bean.getEndTime()));
        res.setTaskId(bean.getTaskId());
        return res;
    }

}
